package com.muyan.subject.impl;

import com.muyan.observer.ObServer;
import com.muyan.subject.AbstractSubject;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: YLTDMenglc
 * @Date: 2019/6/11
 * @Time: 12:25
 * @Description:具体的主题
 */
public class WeChatSubject implements AbstractSubject {
    /**
     * 存放这些主题
     *
     * @param obServer
     */
    private List<ObServer> obServerList = new ArrayList<ObServer>();

    @Override
    public void addObserver(ObServer observer) {
        obServerList.add(observer);
    }

    @Override
    public void deleteObserver(ObServer observer) {
        obServerList.remove(observer);
    }

    @Override
    public void notifyObServer(String msg) {
        System.out.println("开始设置微信群发消息：" + msg);
        // 调用观察者通知方案
        for(int i = 0;i<obServerList.size();i++){
            ObServer obServer = obServerList.get(i);
            // 调用该方法通知 获取具体的消息  群发
            obServer.update(msg);
        }
    }
}
